package demo;

class Animal {
    public String name;
    public int age;
    static {
        System.out.println("Animal静态代码块");
    }
    {
        System.out.println("Animal实例（构造）代码块");
    }

    public Animal() {
        System.out.println("Animal不带参数的构造方法");
    }
    //构造方法
    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public void eat() {
        System.out.println(this.name+" 正在吃饭");
    }
}
class Dog extends Animal{
    public String g;
/*    public Dog() {
        super();
    }*/
static {
    System.out.println("Dog静态代码块");
}
    {
        System.out.println("Dog实例（构造）代码块");
    }

    public Dog() {
        System.out.println("不带参数的构造方法Dog");
    }
/*    public Dog() {
        super("xiaogou",19);
        g = "df";
    }*/
    public Dog(String name, int age,String g) {
        super(name, age); //只能放第一行，所以不能和this()同时在一个构造方法里
        this.g = g;
    }
    public void bark() {
        System.out.println(this.name+" 正在汪汪汪");
    }
}
class Cat extends Animal{
/*    public Cat() {
        super();
    }*/
static {
    System.out.println("Cat静态代码块");
}
    {
        System.out.println("Cat实例（构造）代码块");
    }

    public Cat() {
        System.out.println("不带参数的构造方法Cat");
    }
/*    public Cat() {
        super("xiaomao",15);
    }*/
    public void mimi() {
        System.out.println(this.name+" 正在喵喵喵");
    }
}
public class Test {
    public static void main(String[] args) {
        //定义的同时可以不初始化，但是只能被初始化一次
        final int a = 10;
        //a = 20;//编译出错
        System.out.println(a);
    }
    public static void main2(String[] args) {
        Dog dog = new Dog();
        System.out.println("=======");
        Cat cat = new Cat();
    }
    public static void main1(String[] args) {
        Dog dog1 = new Dog();
        dog1.eat();
        dog1.bark();
        System.out.println("------------");
        Cat cat1 = new Cat();
        cat1.name = "baobao";
        cat1.age = 19;
        cat1.eat();
        cat1.mimi();
    }
}
